//
// Created on 2025/1/10.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#ifndef RLOTTIE_DEMO_XCOM_H
#define RLOTTIE_DEMO_XCOM_H

#include "ArkUINode.h"
#include "string"
#include <ace/xcomponent/native_interface_xcomponent.h>
#include <cstdint>
#include <cstdio>
#include <hilog/log.h>
#include <string>
#include "arkui/native_node.h"
#include "arkui/native_node_napi.h"
#include "arkui/native_interface.h"
#include <native_drawing/drawing_font_collection.h>
#include <native_drawing/drawing_text_typography.h>
#include <native_buffer/native_buffer.h>
#include <map>
#include <sys/mman.h>
#include <native_drawing/drawing_bitmap.h>
#include <native_drawing/drawing_color.h>
#include <native_drawing/drawing_color_filter.h>
#include <native_drawing/drawing_canvas.h>
#include <native_drawing/drawing_pen.h>
#include <native_drawing/drawing_pixel_map.h>
#include <native_drawing/drawing_brush.h>
#include <native_drawing/drawing_path.h>
#include <native_drawing/drawing_rect.h>
#include <native_drawing/drawing_register_font.h>
#include <native_drawing/drawing_filter.h>
#include <native_drawing/drawing_font.h>
#include <native_drawing/drawing_font_collection.h>
#include <native_drawing/drawing_sampling_options.h>
#include <native_drawing/drawing_text_blob.h>
#include <native_drawing/drawing_text_declaration.h>
#include <native_drawing/drawing_text_typography.h>
#include <native_drawing/drawing_types.h>
#include <native_drawing/drawing_typeface.h>
#include "native_drawing/drawing_image.h"
#include <chrono>
#include <iostream>
#include "Getrlottie.h"
#include <cstring>

namespace NativeModule {
class XcomNode : public ArkUINode {
public:
    static OHNativeWindow *nativeWindow;
    XcomNode(float width, float height, std::string fileName);

    static void OnSurfaceChanged(OH_NativeXComponent *component, void *window);
    static void OnSurfaceDestroyed(OH_NativeXComponent *component, void *window);
    static void DispatchTouchEvent(OH_NativeXComponent *component, void *window);
    static void OnSurfaceCreated(OH_NativeXComponent *component, void *window);
    void PrepareSurface();
    void PlayFrame();

private:
    int width_;
    int height_;
    std::string fileName_;
    OH_NativeXComponent_Callback callback_;
//    static XcomponentNode *xcomponentNode_;
    OH_Drawing_Bitmap *cBitmap_ = nullptr;
    OH_Drawing_Canvas *cCanvas_ = nullptr;
    uint32_t *mappedAddr_ = nullptr;
    int fenceFd_ = 0;
    struct NativeWindowBuffer *buffer_ = nullptr;
    BufferHandle *bufferHandle_ = nullptr;
};

} // namespace NativeModule

#endif // RLOTTIE_DEMO_XCOM_H
